﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Configuration;
using Newtonsoft.Json;
using System.Data;
using System.Web.Script.Services;

namespace PromotionEngine
{
    public partial class ItemList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod]
        public static string GetCompanys()
        {
            Promotion pmt = new Promotion();
            DataSet dsPromotion = pmt.GetAllCompany(ConfigurationManager.AppSettings["DATABASE_NAME"].ToString());
            if (dsPromotion != null)
            {
                return JsonConvert.SerializeObject(dsPromotion.Tables[0]);
            }
            return string.Empty;
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public static string GetItems(string keySearch)
        {
            if (keySearch.Trim().Length > 0)
            {
                Promotion pmt = new Promotion();
                DataSet dsPromotion = pmt.GetItemsForSearch(ConfigurationManager.AppSettings["DATABASE_NAME"].ToString(), HttpContext.Current.Session["CompanyCode"].ToString(),
                   keySearch);
                if (dsPromotion != null)
                {
                    return JsonConvert.SerializeObject(dsPromotion.Tables[0]);
                }
            }
            return string.Empty;
        }
    }
}